package com.module.my.adapter.holder

import android.graphics.Color
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import com.module.app.bean.SkinBean
import com.module.app.utils.MySkinUtils
import com.module.base.base.adapter.BaseViewHolder
import com.module.base.utils.CollectionUtil
import com.module.app.utils.GlideUtils
import com.module.my.R
import com.module.my.databinding.MyItemSkinBinding

class SkinHolder(parent: ViewGroup) : BaseViewHolder<com.module.app.bean.SkinBean, MyItemSkinBinding>(parent) {

    override fun initView() {
        super.initView()
        addOnClickListener(R.id.tv_preview)
    }

    override fun convert(bean: com.module.app.bean.SkinBean, position: Int) {
        mDatabind.tvPreview.visibility = if (bean.isVip && !CollectionUtil.isEmptyOrNull(bean.preview)) View.VISIBLE else View.GONE
        mDatabind.vTop.visibility = if (position == 0) View.VISIBLE else View.GONE
        mDatabind.tvName.text = bean.name
        mDatabind.ivHead.setBackgroundColor(Color.parseColor(bean.color))
        mDatabind.ivHeadCircle.visibility = if (TextUtils.isEmpty(bean.skinName)) View.VISIBLE else View.GONE
        if (TextUtils.isEmpty(bean.head)) {
            com.module.app.utils.GlideUtils.load(
                mDatabind.ivHead.context,
                mDatabind.ivHead,
                R.color.transparent,
                R.color.transparent
            )
        } else {
            com.module.app.utils.GlideUtils.loadNet(mDatabind.ivHead.context, mDatabind.ivHead, bean.head)
        }
        mDatabind.tvDesc.text = bean.desc
        mDatabind.tvDesc.visibility = if (TextUtils.isEmpty(bean.desc)) View.GONE else View.VISIBLE
        mDatabind.tvUpdate.visibility = if (com.module.app.utils.MySkinUtils.isUpdate(bean)) View.VISIBLE else View.GONE
        mDatabind.vVip.visibility = if (bean.isVip) View.VISIBLE else View.GONE
        setSelect()
    }

    fun setSelect() {
        mDatabind.ivSelect.setImageResource(if (data.isSelect) R.drawable.app_ic_checkbox_select else R.drawable.app_ic_checkbox)
    }
}